"use strict";
const common_vendor = require("../../../common/vendor.js");
const api_workGuide_index = require("../../../api/workGuide/index.js");
const stores_search = require("../../../stores/search.js");
if (!Array) {
  const _easycom_up_input2 = common_vendor.resolveComponent("up-input");
  const _easycom_up_toast2 = common_vendor.resolveComponent("up-toast");
  (_easycom_up_input2 + _easycom_up_toast2)();
}
const _easycom_up_input = () => "../../../node-modules/uview-plus/components/u-input/u-input.js";
const _easycom_up_toast = () => "../../../node-modules/uview-plus/components/u-toast/u-toast.js";
if (!Math) {
  (_easycom_up_input + _easycom_up_toast)();
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  setup(__props) {
    const searchStore = stores_search.useSearchStore();
    const keyWord = common_vendor.ref("");
    const uToastRef = common_vendor.ref(null);
    const showSearchResult = common_vendor.ref(false);
    const searchResult = common_vendor.ref([]);
    const search = () => {
      if (keyWord.value) {
        api_workGuide_index.searchWorkGuide({ keyWord: keyWord.value }).then((res) => {
          const { data } = res;
          searchStore.setHistory([
            keyWord.value,
            ...searchStore.hisList.filter(
              (item) => item != keyWord.value
            )
          ]);
          searchResult.value = data ?? [];
          showSearchResult.value = true;
        }).catch((err) => {
          uToastRef.value.show({
            type: "error",
            message: err
          });
        });
      } else {
        uToastRef.value.show({
          type: "warning",
          message: "请输入搜索关键词"
        });
      }
    };
    const scanDetail = (item) => {
      common_vendor.index.navigateTo({
        url: `/subPages/crowd/workGuide/detail?id=${item.id}`
      });
    };
    const resetData = () => {
      keyWord.value = "";
      showSearchResult.value = false;
      common_vendor.index.navigateBack({
        delta: 1
      });
    };
    const searchHistory = (item) => {
      keyWord.value = item;
      search();
    };
    common_vendor.onShow(() => {
      keyWord.value = "";
      showSearchResult.value = false;
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.o(search),
        b: common_vendor.o(search),
        c: common_vendor.o(($event) => showSearchResult.value = false),
        d: common_vendor.o(($event) => common_vendor.isRef(keyWord) ? keyWord.value = $event : null),
        e: common_vendor.p({
          color: "#000",
          placeholder: "搜索关键词",
          placeholderStyle: {
            color: "#BBBBBB",
            fontSize: "31rpx"
          },
          prefixIcon: "search",
          prefixIconStyle: "font-size: 50rpx;color: #BBBBBB;",
          shape: "circle",
          border: "surround",
          clearable: true,
          focus: true,
          modelValue: common_vendor.unref(keyWord)
        }),
        f: common_vendor.o(resetData),
        g: common_vendor.unref(showSearchResult)
      }, common_vendor.unref(showSearchResult) ? common_vendor.e({
        h: common_vendor.t(common_vendor.unref(searchResult).length),
        i: common_vendor.unref(searchResult).length
      }, common_vendor.unref(searchResult).length ? {
        j: common_vendor.f(common_vendor.unref(searchResult), (item, index, i0) => {
          return {
            a: common_vendor.t(item.itemName),
            b: index,
            c: common_vendor.o(($event) => scanDetail(item), index)
          };
        })
      } : {}) : common_vendor.e({
        k: common_vendor.unref(searchStore).hisList.length
      }, common_vendor.unref(searchStore).hisList.length ? {
        l: common_vendor.o(
          //@ts-ignore
          (...args) => common_vendor.unref(searchStore).clearHistory && common_vendor.unref(searchStore).clearHistory(...args)
        )
      } : {}, {
        m: common_vendor.unref(searchStore).hisList.length
      }, common_vendor.unref(searchStore).hisList.length ? {
        n: common_vendor.f(common_vendor.unref(searchStore).hisList, (item, index, i0) => {
          return {
            a: common_vendor.t(item),
            b: index,
            c: common_vendor.o(($event) => searchHistory(item), index)
          };
        })
      } : {}), {
        o: common_vendor.sr(uToastRef, "f6fd80c8-1", {
          "k": "uToastRef"
        })
      });
    };
  }
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-f6fd80c8"]]);
wx.createPage(MiniProgramPage);
